package com.sky.wsp.spring.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wangshaopeng@talkweb.com.cn
 * @desccription 在此输入描述
 * @date 2022/4/25
 */
@RestController
@RequestMapping("path")
public class PathPatternController {

    @GetMapping("/exact")
    public String pathExact(HttpServletRequest request) {
        return "pathExact:" + request.getRequestURI();
    }

    @GetMapping("/question?")
    public String pathQuestion(HttpServletRequest request) {
        return "pathQuestion:" + request.getRequestURI();
    }

    @GetMapping("/question?Ext")
    public String pathQuestionExt(HttpServletRequest request) {
        return "pathQuestionExt:" + request.getRequestURI();
    }

    @GetMapping("/param/{p}")
    public String pathParam(@PathVariable("p") String p, HttpServletRequest request) {
        return "pathParam:" + request.getRequestURI() + ", pathVariable:" + p;
    }

    @GetMapping("/common/*")
    public String pathCommon(HttpServletRequest request) {
        return "pathCommon:" + request.getRequestURI();
    }

    @GetMapping("/common/*aa/ext1")
    public String pathCommonExt1(HttpServletRequest request) {
        return "pathCommonExt1:" + request.getRequestURI();
    }

    @GetMapping("/common/*/ext2")
    public String pathCommonExt2(HttpServletRequest request) {
        return "pathCommonExt2:" + request.getRequestURI();
    }

    @GetMapping("/{year:(?:19|20)\\d{2}}")
    public String pattern(HttpServletRequest request) {
        return "pattern:" + request.getRequestURI();
    }

    @GetMapping("/{p}/**")
    public String compose1(@PathVariable("p") String p, HttpServletRequest request) {
        return "compose1:" + request.getRequestURI() + ", pathVariable:" + p;
    }

//    @GetMapping("/{p}/**/2")
//    public String compose2(@PathVariable("p") String p, HttpServletRequest request) {
//        return "compose2:" + request.getRequestURI() + ", pathVariable:" + p;
//    }

    @GetMapping("/**")
    public String others(HttpServletRequest request) {
        return "others:" + request.getRequestURI();
    }



}
